package com.fan.shop.services;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;

import com.fan.shop.dao.PurchaseLineDao;
import com.fan.shop.domain.PurchaseLine;
import com.fan.shop.model.userclass.PurchaseLineUserClass;

@Named("purchaseLineService")
@Transactional(readOnly = true)
public class PurchaseLineServiceImpl implements PurchaseLineService {

	@Inject
	@Named("purchaseLineDao")
	private PurchaseLineDao purchaseLineDao;
	
	
	public PurchaseLineDao getPurchaseLineDao() {
		return purchaseLineDao;
	}

	public void setPurchaseLineDao(PurchaseLineDao purchaseLineDao) {
		this.purchaseLineDao = purchaseLineDao;
	}

	@SuppressWarnings("rawtypes")
	public List getList() {
		return purchaseLineDao.getAllPurchaseLines();
	}

	public int getColumnsSize() {
		return purchaseLineDao.getAllPurchaseLines().size();
	}

	public PurchaseLineUserClass copy(Object obj) {
		PurchaseLine purchaseLine = (PurchaseLine)obj;
		PurchaseLineUserClass purchaseLineUserClass = new PurchaseLineUserClass();
		purchaseLineUserClass.setPoNumber(purchaseLine.getId().getPoNumber());
		purchaseLineUserClass.setItemCode(purchaseLine.getId().getItemCode());
		purchaseLineUserClass.setPrice(purchaseLine.getPrice());
		purchaseLineUserClass.setQuantity(purchaseLine.getQuantity());
		return purchaseLineUserClass;
	}

	public PurchaseLine getPurchaseLine(String poNumber, String lineNumber) {
		return purchaseLineDao.getPurchaseLine(poNumber, lineNumber);
	}

	public List<PurchaseLine> getAllPurchaseLines() {
		return purchaseLineDao.getAllPurchaseLines();
	}

	@Transactional(readOnly = false)
	public void addPurchaseLine(PurchaseLine purchaseLine) {
		purchaseLineDao.addPurchaseLine(purchaseLine);
	}

	@Transactional(readOnly = false)
	public void updatePurchaseLine(PurchaseLine purchaseLine) {
		purchaseLineDao.updatePurchaseLine(purchaseLine);
	}

	@Transactional(readOnly = false)
	public void deletePurchaseLine(PurchaseLine purchaseLine) {
		purchaseLineDao.deletePurchaseLine(purchaseLine);
	}

	public boolean hasPurchaseLine(String poNumber, String lineNumber) {
		return purchaseLineDao.hasPurchaseLine(poNumber, lineNumber);
	}

	public List<String> getColumnNames() {
		return purchaseLineDao.getColumnNames();
	}

}
